package com.zhen.aikan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhen.aikan.entity.VodDetail;
import com.zhen.aikan.vo.Result;
import com.zhen.aikan.service.IVodDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lijiazhen
 * @since 2023-09-11
 */
@Api(tags = "VodDetail控制器")
@RestController
@RequestMapping("/api/vod")
public class VodDetailController {
    @Autowired
    private IVodDetailService vodDetailService;

    @ApiOperation("根据类型名获取热门推荐")
    @GetMapping("/hotVod")
    public Result hotVod(@NotNull @RequestParam(name = "typeName") String typeName,
                               @RequestParam(name = "current",defaultValue = "1") Integer current,
                               @RequestParam(name = "size",defaultValue = "10") Integer size){
        Page<Map<String, Object>> page = vodDetailService.getHotAnimationWithPage(typeName, current, size);
        return Result.ok(page);
    }

    @ApiOperation("根据类型地区获取最近更新的热门")
    @GetMapping("/hotVodMonthTypeArea")
    public Result hotVodMonthTypeArea(@RequestParam(name = "typeName") String typeName,
                                      @RequestParam(name = "area",defaultValue = "") String area,
                                      @RequestParam(name = "size",defaultValue = "10") Integer size){
        List<VodDetail> vods = vodDetailService.getHotVodByMaonthTypeArea(typeName,area,size);
        return Result.ok(vods);
    }

    @ApiOperation("根据类型地区获取月点击总量最多的热门热门")
    @GetMapping("/hotVodMonthTypeAreaWithHitsMonth")
    public Result hotVodMonthTypeAreaWithHitsMonth(@RequestParam(name = "typeName") String typeName,
                                      @RequestParam(name = "area",defaultValue = "") String area,
                                      @RequestParam(name = "size",defaultValue = "10") Integer size){
        List<VodDetail> vods = vodDetailService.getHotVodMonthTypeAreaWithHitsMonth(typeName,area,size);
        return Result.ok(vods);
    }

    @ApiOperation("根据id获取影片详细信息")
    @GetMapping("/vodDetail/{vodId}")
    public Result vodDetailById(@PathVariable long vodId){
        VodDetail vodDetail = vodDetailService.getVodDetailById(vodId);
        return Result.ok(vodDetail);
    }

    /**
     * @param other 最新 最热 高分
     */
    @ApiOperation("根据条件过滤出需要的影片")
    @GetMapping("/vods")
    public Result getVodByCondition(@RequestParam(name = "pTypeId") Integer pTypeId,
                                    @RequestParam(name = "sTypeId") Integer sTypeId,
                                    @RequestParam(name = "area") String area,
                                    @RequestParam(name = "other") String other,
                                    @RequestParam(name = "current",defaultValue = "1") Integer currentPage,
                                    @RequestParam(name = "size",defaultValue = "39") Integer size){
        Page<Map<String, Object>> page = vodDetailService.getVodByCondition(pTypeId,sTypeId,area,other,currentPage,size);
        return Result.ok(page);
    }

    @ApiOperation("获取关于影片类型的当前月的影片排行榜")
    @GetMapping("/leaderboard/{typeName}/{current}/{size}")
    public Result getVodLeaderboardByType(@PathVariable String typeName,
                                          @PathVariable Integer current,
                                          @PathVariable Integer size){
        Page<Map<String, Object>> page = vodDetailService.getVodLeaderboardByTypeName(typeName,current,size);
        return Result.ok(page);
    }

    @ApiOperation("获取猜你喜欢的视频信息(相似类，相同地域，相似标签，较热门，取前15个)")
    @GetMapping("/getGuessYouLike")
    public Result getGuessYouLike(@RequestParam(name = "class") String vodClass,
                                  @RequestParam(name = "area") String area,
                                  @RequestParam(name = "tag") String tag){
        List<VodDetail> vodDetailList = vodDetailService.getGuessYouLike(vodClass,area,tag);
        return Result.ok(vodDetailList);
    }


    @ApiOperation("根据星期几和类型来获取最近一个月更新的视频")
    @GetMapping("/getVodsByWeekType")
    public Result getVodsByWeekType(@RequestParam(name = "week") String week,
                                    @RequestParam(name = "type") String typeName,
                                    @RequestParam(name = "area",defaultValue = "") String area){
        List<VodDetail> vodDetailList = vodDetailService.getVodsByWeekType(week,typeName,area);
        return Result.ok(vodDetailList);
    }
}
